package com.xbongbong.saas.domain.dao;

import com.xbongbong.saas.domain.entity.BusinessProductEntity;
import com.xbongbong.saas.domain.entity.ReturnedPurchaseProductEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/2/21 15:16
 * @since v1.0
 */
@Repository
@Mapper
public interface ReturnedPurchaseProductDao {
    /**
     * 插入数据
     *
     * @param returnedPurchaseProduct 采购退货单产品实体数据
     * @return 是否成功
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     **/
    Integer insert(ReturnedPurchaseProductEntity returnedPurchaseProduct);
    /**
     * 更新数据
     *
     * @param returnedPurchaseProduct 采购退货单产品实体数据
     * @return 是否成功
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     **/
    Integer update(ReturnedPurchaseProductEntity returnedPurchaseProduct);
    /**
     * 根据主键删除记录
     *
     * @param key    主键
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByKey(@Param("key") Long key, @Param("corpid") String corpid);
    /**
     * 删除采购退货单下的所有产品根据采购退货单Id
     *
     * @param returnPurchaseId    id集合
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByReturnPurchaseId(@Param("returnPurchaseId") Long returnPurchaseId, @Param("corpid") String corpid);
    /**
     * 删除多条采购退货单下下的所有产品
     *
     * @param returnPurchaseIdIn    id集合
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByReturnPurchaseIdIn(@Param("returnPurchaseIdIn") List<Long> returnPurchaseIdIn, @Param("corpid") String corpid);
    /**
     * 获取一条采购退货单产品数据
     *
     * @param key 采购合同产品ID
     * @param corpid 公司id
     * @return ReturnedPurchaseProductEntity 一条数据实体
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    ReturnedPurchaseProductEntity getByKey(@Param("key") Long key, @Param("corpid") String corpid);
    /**
     * 多参数查询多条数据
     *
     * @param param 参数集合
     * @return List<ReturnedPurchaseProductEntity> 数据集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    List<ReturnedPurchaseProductEntity> findEntitys(@Param("param") Map<String, Object> param);
    /**
     * 获取采购退货单ID集合
     *
     * @param param 参数集合
     * @return  List<Long> Id集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    List<Long> findReturnedPurchaseIds(@Param("param") Map<String, Object> param);
    /**
     * 获取记录数
     *
     * @param param 参数集合
     * @return  Integer Id集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer getEntitysCount(@Param("param") Map<String, Object> param);
    /**
     * 关联查询
     *
     * @param param 参数集合
     * @return  List<ReturnedPurchaseProductEntity> Id集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    List<ReturnedPurchaseProductEntity> findEntitysJoinProduct(@Param("param") Map<String, Object> param);

    List<BusinessProductEntity> findProductNum(@Param("param") Map<String,Object> param);

    Integer findProductNumCount(@Param("param") Map<String,Object> param);

    Integer updateBatch(@Param("list") List<ReturnedPurchaseProductEntity> updateList, @Param("corpid") String corpid);

    Integer updateOutstockBatch(@Param("list") List<ReturnedPurchaseProductEntity> updateList, @Param("corpid") String corpid);

    Long isProductSubAttrExist(@Param("attr") String attr, @Param("corpid") String corpid,@Param("isArray") Integer isArray);

    Double summaryByAttr(@Param("field")  String field,@Param("corpid") String corpid,@Param("refId")  Long refId,@Param("productIdIn")  List<Long> productIdIn);

    Double summaryByAttrFromOutSide(@Param("field")  String field,@Param("corpid") String corpid,@Param("refId")  Long refId,@Param("productIdIn")  List<Long> productIdIn);

    Double calcuateByAttrFromOutSide(@Param("field1")String field1,@Param("field2") String field2,@Param("corpid") String corpid,@Param("refId") Long refId,@Param("productIdIn") List<Long> productIdIn);

    Long countProductSub(@Param("attr") String attr, @Param("corpid") String corpid, @Param("isArray") Integer isArray);

    List<ReturnedPurchaseProductEntity> getProductWithSubData(@Param("attr") String attr, @Param("corpid") String corpid, @Param("isArray") Integer isArray, @Param("idGte") Long idGte, @Param("limit") Integer limit);

    Integer deleteBatch(@Param("list")List<Long> deleteList, @Param("corpid") String corpid, @Param("del") Integer del);
    /**
     * 批量更新
     * @param list
     * @param corpid
     * @return
     */
    Integer updateMulti(@Param("list") List<ReturnedPurchaseProductEntity> list,@Param("corpid") String corpid);

    List<ReturnedPurchaseProductEntity> getReturnedPurchaseProductById(@Param("map")Map<Long, Long>outstockFlowAndRefurned, @Param("corpid")String corpid);

    /**
     * 批量插入
     * @param productAddList
     * @return
     */
    Integer insertBatch(@Param("list") List<ReturnedPurchaseProductEntity> productAddList);
}
